package AplManager.models;



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Israel Agyeman-Premp
 */
public class Team {

    /**
     * @param args the command line arguments
     */
    String teamID;
    String teamName;
    Player[] players;
    int curSize;
    
    public Team(String ID,String name){
        teamID = ID;
        teamName = name;
        players = new Player[100];
        curSize = 0;

    }
    public int getCurSize(){
   return curSize;
   }
   public String getTeamName(){
   return teamName;
   }
   public String getTeamID(){
   return teamID;
   }
   public void addPlayer(Player newPlayer){
   players[curSize] = newPlayer;
   curSize++;
   }   
   public void updatePlayer(int num, Player player){
       players[num].fname = player.getFirstName();
       players[num].lname = player.getlastName();
       players[num].number = player.getNumber();
       players[num].position = player.getPosition();
       players[num].assists = player.getAssists();
       players[num].goals = player.getGoals();
       
       System.out.println("I worked");
        System.out.println(players[num].getAssists());
       }
   
   public void deletePlayer(int playerNum){
      int num = 0;
   for(int i= 0; i < curSize; i++){
       if(players[i].getNumber()==(playerNum)){
        if(i < curSize-1){
           players[i] = players[i+1];
        }
        num =i;
       }
   }
   for(int i= num; i< curSize;i++){
     if(i < curSize-1){
           players[i] = players[i+1];
        }
   }
   players[curSize] = null;
   curSize--;
   }
    public Player[] getPlayers(){
    return players;
    }
    
    public void printArray(){
        Player[] a = players;
	for(int i =0; i < curSize; i++){
	  System.out.println(a[i].fname);
	}
       System.out.println(curSize);
}
       public String[] createSrtLineUp(){
         String[] lineUp = new String[curSize];
	for(int i =0; i < curSize; i++){
	  if(players[i].isInStartingLineUp() == true){
            lineUp[i]=  players[i].fname+" "+players[i].lname+"     "+players[i].number+"       "+players[i].position;
          }
	}
        return lineUp;     
}
    public static void main(String[] args) {
        // TODO code application logic here
        Team team1 = new Team("team1","Field Marshalls");
        
        Player player1 = new Player("George","Assan","LB",6);
        Player player2 = new Player("James","Assan","LB",5);
        Player player3 = new Player("Max","Assan","LB",7);
        Player player4 = new Player("Frank","Assan","LB",8);
        
        team1.addPlayer(player1);
        team1.addPlayer(player2);
        team1.addPlayer(player3);
        team1.addPlayer(player4);
        
        team1.printArray();
        
        team1.deletePlayer(player3.getNumber());
         team1.printArray();
        
        
    }
}